<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + " ://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<jsp:include page="root_public.jsp"/>
<title>权限管理</title>
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
          <a href="javascript:;">首页</a>
          <a href="<%=path%>/adminRule">权限管理</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加权限','<%=path%>/ruleAdd',450,480)"><i class="layui-icon">
        </i>添加
        </button>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>权限名称</th>
            <th>权限规则</th>
            <th>权限</th>
            <th>管理者描述</th>
            <th>权重</th>
            <th>创建时间</th>
            <th>操作</th>
        </thead>
        <tbody class="tbody">
        </tbody>
    </table>
</div>
<script>
    var $tbody = $('.tbody');
    menuLists();

    function menuLists() {
        $tbody.html("");
        $.ajax({
            type: "post",
            url: "<%=path%>/menu/findList",
            async: true,
            dataType: "json",
            success: function (data) {
                var datas = data.data.menuList;
                for (var i = 0; i < datas.length; i++) {
                    var datass = datas[i],
                        remarks = "";
                    if (datass.remarks != null) {
                        remarks = datass.remarks;
                    }
                    console.log(datass);
                    var $html = $('        <tr>\n' +
                        '            <td>' + datass.name + '</td>\n' +
                        '            <td>' + datass.href + '</td>\n' +
                        '            <td>' + datass.permission + '</td>\n' +
                        '            <td>' + remarks + '</td>\n' +
                        '            <td>' + datass.sort + '</td>\n' +
                        '            <td>' + datass.createDate + '</td>\n' +
                        '            <td class="td-manage">\n' +
                        '                <a title="编辑" onclick="x_admin_show(\'编辑\',\'<%=path%>/ruleEdit?id=' + datass.id + '\',450,450)" href="javascript:;">\n' +
                        '                    <i class="layui-icon">&#xe642;</i>\n' +
                        '                </a>\n' +
                        '                <a title="删除" onclick="member_del(this)" href="javascript:;">\n' +
                        '                    <i class="layui-icon">&#xe640;</i>\n' +
                        '                </a>\n' +
                        '                <a style="display: none;position:absolute;" class="ID">' + datass.id + '</a>\n' +
                        '            </td>\n' +
                        '        </tr>'
                    );
                    $tbody.append($html);
                }
            }
        });
    }

    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //以上模块根据需要引入

        layer.ready(function () { //为了layer.ext.js加载完毕再执行
            layer.photos({
                photos: '#x-img'
                //,shift: 5 //0-6的选择，指定弹出图片动画类型，默认随机
            });
        });
    });


    /*删除*/
    function member_del(obj) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            var $id = $(obj).siblings(".ID").text();
            $.ajax({
                type: "post",
                url: "<%=path%>/menu/delete",
                async: true,
                dataType: "json",
                data: {
                    "id": $id
                },
                success: function (data) {
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!', {icon: 1, time: 600});
                }
            });
        });
    }
</script>

</body>

</html>